<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2014 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace Portal\Controller;

use Common\Controller\HomebaseController;

/**
 * 首页
 */
class IndexController extends HomebaseController
{

    //首页
    public function index()
    {
        $this->display(":index");
    }

    /**
     * 用户登录
     */
    public function user_login()
    {
        creatToken();
        $this->display();
    }

    /**
     * 用户注册
     */
    public function user_register()
    {
        $this->display();
    }

    /**
     * 用户中心
     */
    public function user_center()
    {
        //dump(session('userinfo'));
        $this->display();
    }

    /**
     * 取送订单
     */
    public function take_send()
    {
        //dump(session('userinfo'));
        //物品类型=========
        $res_type = M('res_type');
        $this->assign('res_type', $res_type->where(array('type' => 1,))->order('sort asc')->select());
        //团队======
        $company = M('company');
        $this->assign('company', $company->order('sort asc')->select());

        $app_users = M('app_users');
        $purse_balance = $app_users->where(array('user_id'=>session('userinfo.user_id')))->field('purse_balance')->find();
        $this->assign('purse_balance',$purse_balance['purse_balance']);
        //vendor('wxpay.WeixinNative');
        //$WeixinNative = new \WeixinNative();
        //$url2 = $WeixinNative->pc_weixin_pay();
        //dump($url2);
        $this->display();

    }


    /**
     * 代买
     */
    public function replaced_buy()
    {
        //物品类型=========
        $res_type = M('res_type');
        $this->assign('res_type', $res_type->where(array('type' => 1,))->order('sort asc')->select());
        $this->display();
    }

    /**
     * 排队
     */
    public function line_up()
    {
       //物品类型=========
        $res_type = M('res_type');
        $this->assign('res_type', $res_type->where(array('type' => 1,))->order('sort asc')->select());
        $this->display();
    }

    /**
     * 用户信息
     */
    public function user_info()
    {
        $this->display();
    }

    /**
     * 消费记录
     */
    public function consume_log()
    {
        $this->display();
    }

    /**
     * 用户安全全退出
     */
    public function user_logout()
    {
        session_unset();
        session_destroy();
        $this->redirect(U('user_login'));
    }

    /**
     * 订单记录
     */
    function order_log(){
//       dump($_SESSION["user"]); 
//       $id = sp_get_current_userid();
//       dump($id);
//       dump(session('userinfo.user_id'));
//        $user_id = session('userinfo.user_id');
//     dump($_SESSION);
        $type = I('type');
        switch((int)$type){
            //所有订单
            case 1:

                break;
            //待支付订单
            case 2:
                break;
            //待接单订单
            case 3:
                break;
            //进行中的订单
            case 4:
                break;
            //已完成的订单
            case 5:
                break;
            //已取消的订单
            case 6:
                break;
        }
        
        $order_model = M("order o");
        
//        $count = $order_model->where(array('o.user_id'=> $user_id))->join('left join db_app_users u on u.user_id = o.user_id ')->count();
//        import("Org.Util.Pagemumayi");
//        $page = new \Pagemumayi($count,20);
//        //分页跳转的时候保证查询条件
//        foreach($formget as $key=>$val) {
//            $page->parameter .= 'formget['."$key"."]=".urlencode($val)."&";
//        }
        $count = $order_model->where(array('o.user_id'=> $user_id))->join('left join db_app_users u on u.user_id = o.user_id  ')->count();
        import("Org.Util.Pagemumayi");
        $page = new \Pagemumayi($count,10);
        //分页跳转的时候保证查询条件
        foreach($formget as $key=>$val) {
            $page->parameter .= 'formget['."$key"."]=".urlencode($val)."&";
        }
        $order_data = $order_model
                    ->field("o.order_type,o.real_amount,o.is_reservation,o.send_address,o.reci_address")
                    ->join('left join db_app_users u on u.user_id = o.user_id')
                    ->where(array('o.user_id'=> $user_id) )
                    ->order("o.order_id desc")
                    ->limit($page->firstRow . ',' . $page->listRows)
                    ->select();
       // dump($order_data);
        if($order_data){
             $this->assign('total_count', $count);
             $this->assign('order_data',$order_data); 
             $this->assign("page", $page->show('Admin')); 
        }else{
            
        }
        //dump($order_data);
        
        $this->display();
    }

    /**
     * 微信二维码生成
     */
    public function bar_code()
    {
        vendor('wxpay.WeixinNative');
        $WeixinNative = new \WeixinNative();
        //dump(I('out_trade_no'));
        //dump(I('total_fee'));
        //dump(U('Api/Portal/weixinNotify'));
        $url2 = $WeixinNative->pc_weixin_pay(I('out_trade_no'),I('total_fee')*100,U('Api/Portal/weixinNotify'));
        //dump($url2);
        $this->assign('url2', $url2);
        $this->assign('out_trade_no', I('out_trade_no'));
        $this->display();
    }


}


